<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace AlibabaCloud\Client\Traits;

trait EndpointTrait
{
    private static $hosts = [];
    public static function resolveHost($product, $regionId = \AlibabaCloud\Client\Regions\LocationService::GLOBAL_REGION)
    {
        \AlibabaCloud\Client\Filter\ApiFilter::product($product);
        \AlibabaCloud\Client\Filter\ClientFilter::regionId($regionId);
        if(isset(self::$hosts[$product][$regionId])) {
            return self::$hosts[$product][$regionId];
        }
        $domain = \AlibabaCloud\Client\Config\Config::get("endpoints." . $product . "." . $regionId);
        if(!$domain) {
            $regionId = \AlibabaCloud\Client\Regions\LocationService::GLOBAL_REGION;
            $domain = \AlibabaCloud\Client\Config\Config::get("endpoints." . $product . "." . $regionId, "");
        }
        return $domain;
    }
    public static function addHost($product, $host, $regionId = \AlibabaCloud\Client\Regions\LocationService::GLOBAL_REGION)
    {
        \AlibabaCloud\Client\Filter\ApiFilter::product($product);
        \AlibabaCloud\Client\Filter\HttpFilter::host($host);
        \AlibabaCloud\Client\Filter\ClientFilter::regionId($regionId);
        self::$hosts[$product][$regionId] = $host;
        \AlibabaCloud\Client\Regions\LocationService::addHost($product, $host, $regionId);
    }
    public static function resolveHostByRule(\AlibabaCloud\Client\Request\Request $request)
    {
        $regionId = $request->realRegionId();
        $network = $request->network ?: "public";
        $suffix = $request->endpointSuffix;
        if($network === "public") {
            $network = "";
        }
        if($request->endpointRegional === "regional") {
            return $request->product . $suffix . $network . "." . $regionId . ".aliyuncs.com";
        }
        if($request->endpointRegional === "central") {
            return $request->product . $suffix . $network . ".aliyuncs.com";
        }
        throw new \InvalidArgumentException("endpointRegional is invalid.");
    }
}

?>